package com.zxm.sunshineaiary.view.flinggallery.view;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.GestureDetector.OnGestureListener;

import com.zxm.sunshineaiary.view.flinggallery.info.FingGalleryInfo;
import com.zxm.sunshineaiary.view.flinggallery.util.Operation;


public class FlingGestureDetector implements OnGestureListener {

	private FingGalleryInfo mFGInfo;
	private FingGallery mFingGallery;
	private Operation mOperation;
	private View[] mViews;
	private int viewHigh = FingGalleryInfo.child_view_high;

	private static boolean FingGalleryInfoFlag = true;// ��Ϊ��Ļ�ĳ�������ֻ���ڼ��ؽ�����ã����Է��ڻ�����

	public FlingGestureDetector(FingGallery mFingGallery) {
		this.mFingGallery = mFingGallery;
		this.mViews = mFingGallery.getViews();
		this.mOperation = Operation.getOperationInstatnce(mFingGallery);
		this.mFGInfo = FingGalleryInfo.getFGInfoInstance(mFingGallery);
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
			float distanceY) {

		if (FingGalleryInfoFlag) {
			mFGInfo.setmViewTop(mFingGallery.getTop());
			mFGInfo.setmViewBottem(mFingGallery.getBottom());
			mFGInfo.setmViewLeft(mFingGallery.getLeft());

			FingGalleryInfoFlag = false;
		}

		isScroll();
		int y = (int) -(e2.getRawY() - e1.getRawY());
		mOperation.startScroll((int) distanceX, (int) y);
		return true;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
			float velocityY) {
		Log.v("FlingGestureDetector", "onFling");
		if (Math.abs(velocityY) > ViewConfiguration.get(
				mFingGallery.getContext()).getScaledMinimumFlingVelocity()) {
			Log.v("FlingGestureDetector", "if");
		}
		return true;
	}

	@Override
	public void onLongPress(MotionEvent e) {

	}

	@Override
	public void onShowPress(MotionEvent e) {
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return false;
	}

	@Override
	public boolean onDown(MotionEvent e) {
		return false;
	}

	private void isScroll() {
		if (mFGInfo.isClick()) {
			mFGInfo.setClick(false);
		}
	}
}
